package trastienda.servlet.usuario;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import trastienda.dao.UsuarioDAO;
import trastienda.excepcion.DAOExcepcion;
import trastienda.modelo.Usuario;

/**
 * Servlet implementation class for Servlet: UsuarioInsertarServlet
 * 
 */
public class UsuarioInsertarServlet extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {
	static final long serialVersionUID = 1L;

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public UsuarioInsertarServlet() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// 
		String a = request.getParameter("idUsuario");
		String b = request.getParameter("Nombres");
		String c = request.getParameter("paterno");
		String d = request.getParameter("materno");
		String e = request.getParameter("clave");
		String f = request.getParameter("area");
                String g = request.getParameter("grupo");
                String h = request.getParameter("mail");

		Usuario vo = new Usuario();
		vo.setIdUsuario(a);
		vo.setNombres(b);
		vo.setPaterno(c);
		vo.setMaterno(d);
                vo.setClave(e);
		vo.setArea(f);
                vo.setGrupo(g);
                vo.setMail(h);

		UsuarioDAO dao = new UsuarioDAO();
		try {
			dao.insertar(vo);
			RequestDispatcher rd = request
					.getRequestDispatcher("/mantenimiento_users.jsp");
			rd.forward(request, response);
		} catch (DAOExcepcion e1) {
			System.err.println("Error");
			RequestDispatcher rd = request.getRequestDispatcher("/error.jsp");
			rd.forward(request, response);
		}

	}
}